package org.example.y24.m12;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个十进制整数：");
        try {
            int num = scanner.nextInt();
            System.out.println("对应的二进制表示为: " + dToB(num));
        } catch (Exception e) {
            System.out.println("输入错误，请确保您输入的是一个有效的整数。");
        } finally {
            scanner.close();
        }
    }

    private static String dToB(int num) {
        if (num == 0) return "0";

        StringBuilder n = new StringBuilder();
        while (num > 0) {
            n.insert(0, num % 2);
            num /= 2;
        }
        return n.toString();
    }
}
